package com.lfp.config.rabbitmq;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description TODO
 * @Author lfp
 * @Date 2022/3/29 22:35
 * @Version 1.0
 */
@Configuration
public class DirectExchangeQueueConfig {

    //交换机
    public static final String DIRECT_EXCHANGE_NAME = "direct_exchange";
    //队列
    public static final String DIRECT_QUEUE_NAME = "direct_queue";
    //路由键 RoutingKey
    public static final String DIRECT_ROUTING_KEY = "key1";


    //声明交换机
    @Bean("directExchange")
    public DirectExchange directExchange(){
        return new DirectExchange(DIRECT_EXCHANGE_NAME);
    }

    //声明队列
    @Bean("directQueue")
    public Queue directQueue(){
        //return new Queue(CONFIRM_QUEUE_NAME);
        return QueueBuilder.durable(DIRECT_QUEUE_NAME).build();
    }

    //绑定
    @Bean("queueBindingExchange")
    public Binding queueBindingExchange(@Qualifier("directQueue") Queue directQueue,
                                        @Qualifier("directExchange") DirectExchange directExchange){
        return BindingBuilder.bind(directQueue).to(directExchange).with(DIRECT_ROUTING_KEY);
    }

}
